﻿using System;

namespace QuanLyKTX
{
    using DAL;
    using System.Linq;

    public partial class frm_ReportStudentList : Telerik.WinControls.UI.RadForm
    {
        public frm_ReportStudentList()
        {
            InitializeComponent();
        }

        private void frm_ReportStudentList_Load(object sender, EventArgs e)
        {
            using (var db = new QuanLyKTXDataContext())
            {
                var results = from p in db.tbl_SinhViens
                              where p.KhoaTaiKhoan == false
                              orderby p.ID
                              select new
                              {
                                  p.MaSinhVien,
                                  Truong = (from t in db.tbl_Truongs where t.MaTruong == p.MaTruong select t.TenTruong).FirstOrDefault(),
                                  Lop = p.MaLop,
                                  p.Ho,
                                  p.Ten,
                                  GioiTinh = p.GioiTinh.Value ? "Nam" : "Nữ",
                                  p.NgaySinh,
                                  p.SoCMND,
                                  p.NoiCap,
                                  p.NgayCap,
                                  p.DiaChi,
                                  p.SoDienThoai,
                                  p.SoDienThoaiCN,
                                  p.Email
                              };

                if (results.Count() > 0)
                {
                    foreach (var result in results)
                    {
                        System.Data.DataRow dRow = dataSetDSSV.Tables[0].NewRow();
                        dRow["MaSinhVien"] = result.MaSinhVien;
                        dRow["Truong"] = result.Truong;
                        dRow["Lop"] = result.Lop;
                        dRow["Ho"] = result.Ho;
                        dRow["Ten"] = result.Ten;
                        dRow["GioiTinh"] = result.GioiTinh;
                        if (result.NgaySinh != null)
                            dRow["NgaySinh"] = result.NgaySinh;
                        dRow["SoCMND"] = result.SoCMND;
                        dRow["NoiCap"] = result.NoiCap;
                        if (result.NgayCap != null)
                            dRow["NgayCap"] = result.NgayCap;
                        dRow["DiaChi"] = result.DiaChi;
                        dRow["SoDienThoai"] = result.SoDienThoai;
                        dRow["SoDienThoaiCN"] = result.SoDienThoaiCN;
                        dRow["Email"] = result.Email;

                        dataSetDSSV.Tables[0].Rows.Add(dRow);
                    }                                    
                    
                    reportViewer_DSSV.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet_DSSV", dataSetDSSV.Tables[0]));
                    reportViewer_DSSV.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
                    reportViewer_DSSV.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth;
                }
            }
            this.reportViewer_DSSV.RefreshReport();
        }
    }
}
